Repository navigation
fix(instagram): verify sessions without legacy query_hash, never password-login on throttles - #3
Merged
Merged
Conversation
…word-login on throttles The session check used instaloader's test_login(), which queries the legacy GraphQL query_hash d6f4427... and turns every error, including Instagram's 401 "Please wait a few minutes" throttle, into "not logged in". The collector then fell back to a scripted password login and rewrote the session file, exactly what triggers checkpoints. The saved feed (Profile.own_profile() + get_saved_posts()) used legacy query_hash queries as well. - Session check: read the sessionid / ds_user_id cookies (missing: logged out, no request), then ask i.instagram.com api/v1/users/<id>/info/ once with max_connection_attempts temporarily set to 1. Only a positive "logged out" answer (login redirect, login_required, other account) falls back to the password login. Throttles, connection errors and unknown errors raise the new InstagramSessionCheckFailed (an InstagramRateLimited, exit code 3) and leave the session file untouched; checkpoints raise InstagramAuthRequired. - Saved feed: private API api/v1/feed/saved/posts/ via get_iphone_json, paginated lazily with max_id, posts built with Post.from_iphone_struct (tolerant fallback node). map_post reads owner, comment count and carousel video children from the private API struct. - translate_error maps AbortDownloadException checkpoints/login redirects to InstagramAuthRequired. - Tests: fake loader records every request; real InstaloaderContext tests with a faked HTTP layer; CLI exit code 3 for a throttled check. - Docs: operations troubleshooting note, CHANGELOG entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two real
extract instagramruns (15:36 and 20:03, 4.5 h apart) failed identically with401 "Please wait a few minutes before you try again."on the legacy GraphQLquery_hashd6f4427… — and, worse, silently fell back to a password login:test_login()queries that legacy hash and swallowsConnectionException, returningNone. A throttle therefore looked like "session invalid", so the collector called_password_login()(the session file was rewritten). Repeated scripted password logins are what triggers Instagram checkpoints.Profile.own_profile()uses the same hash;get_saved_posts()uses another legacy hash (f883d95…). Upstream (4.15.5, master,upcoming/v4.16) is unchanged; see Error 401 - Unauthorized "fail" status, message "Please wait a few minutes before you try again." instaloader/instaloader#2511, #2487.Changes
_check_session): notest_login(). Readssessionid/ds_user_idlocally (missing → logged out, no request), then oneget_iphone_json("api/v1/users/<id>/info/")withmax_connection_attempts=1(restored infinally).login_required, other account) → password login if configured, elseInstagramAuthRequiredInstagramAuthRequired, no password loginInstagramSessionCheckFailed(subclass ofInstagramRateLimited, exit code 3), no password login, session file untouchedapi/v1/feed/saved/posts/(lazymax_idpagination, stops onmore_available=false, missing/repeated cursor, empty page); posts viaPost.from_iphone_structwith a tolerant fallback node.map_postreads owner, plain-int comment counts and carousel video children (with durations) from the private-API struct.AbortDownloadException(checkpoint, login redirect) maps toInstagramAuthRequired.Post.from_shortcode(transcription re-fetch) already uses adoc_idPOST, unchanged.docs/operations.md, CHANGELOG (Unreleased).Test plan
uv run pytest: 994 passed, 4 skipped (was 964/4); new tests for throttled/logged-out/checkpoint/valid checks (password login never called on throttles, exactly one request, attempts restored), feed pagination/early stop/cursor loop, iphone-struct mapping, CLI exit code 3InstaloaderContextwith fakedrequests(no socket): throttled check = one GET; valid run only hitsi.instagram.com/api/v1/…, never aquery_hashruff check,ruff format --check,mypy srccleanpostparse extract instagram --limit 1 --stop-after-known 1(2 requests)🤖 Generated with Claude Code